package com.example.wearing.tools;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.wearing.R;
import com.example.wearing.javabean.Post;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/3/17.
 */
public class KindListAdapter extends ArrayAdapter {
    Context context;
    ArrayList<String> kindList;
    private int nowSelectedIndex = 0; //默认选中

    private static final String TAG = "KindListAdapter";
    public KindListAdapter(Context context,
                       int resource,
                       ArrayList<String> list) {
        super(context, resource, list);
    }



//
//    @Override
//    public int getCount() {
//        return kindList.size();
//    }
//
//    @Override
//    public Object getItem(int position) {
//        return kindList.get(position);
//    }
//
//    @Override
//    public long getItemId(int position) {
//        return position;
//    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View itemView = convertView;
        if (itemView == null) {
            itemView = LayoutInflater.from(getContext()).inflate(R.layout.kind_list,
                    parent,
                    false);
        }

        String item = (String) getItem(position);
        TextView kind_item= (TextView) itemView.findViewById(R.id.kind_item);
        kind_item.setText(item);

        if (position == nowSelectedIndex){
            //设置选中颜色
            kind_item.setBackgroundColor(0xFFFFFFFF);
        }else {
            //未选中
            kind_item.setBackgroundColor(0xFFEBEBEB);
        }

        return itemView;
    }

    public int getNowSelectedIndex() {
        return nowSelectedIndex;
    }

    public void setNowSelectedIndex(int nowSelectedIndex) {
        this.nowSelectedIndex = nowSelectedIndex;
        this.notifyDataSetChanged();//及时通知显示
    }
}
